package com.kujawnode.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @version 1.0
 * @Author kujaw
 * @Date 2025/7/9 13:20
 * @注释
 * 统一封装web层向前端页面返回结果
 */
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class R {

    //表示返回的结果码，比如200,500
    private int code;

    //表示返回的结果信息，比如用户登录状态失败
    private String msg;

    //表示返回的数据，数据可能是一个对象，也可能是是list集合
    private Object data;

    public static R OK(){
        return R.builder()
                .code(CodeEnum.OK.getCode())
                .msg(CodeEnum.OK.getMsg())
                .build();
    }

    public static R OK(int code, String msg){
        return R.builder()
                .code(code)
                .msg(msg)
                .build();
    }

    public static R OK(Object data){
        return R.builder()
                .code(CodeEnum.OK.getCode())
                .msg(CodeEnum.OK.getMsg())
                .data(data)
                .build();
    }

    public static R FAIL(){
        return R.builder()
                .code(CodeEnum.FALT.getCode())
                .msg(CodeEnum.FALT.getMsg())
                .build();
    }

    public static R FAIL(String msg){
        return R.builder()
                .code(CodeEnum.FALT.getCode())
                .msg(msg)
                .build();
    }

    public static R FAIL(CodeEnum codeEnum){
        return R.builder()
                .code(codeEnum.getCode())
                .msg(codeEnum.getMsg())
                .build();
    }
}
